  var flag = 0;
        function sort(page_number)
        {
            if(flag == 1)
            {
                $(".sort").css("display","block");
                var idCate= $("#selCategory").val();
                var sortby =$(".sortb").val(); 
                var rank =$(".sorta").val(); 
                if(idCate != -1)
                {
                $.ajax({
                        type: "post",
                        url:"/sort/index",
                        data:{"idCategory":idCate,"page":page_number,"sortby":sortby,"rank":rank},
                        async:false,
                        success:function(data)
                          {

                                 $(".maincontent").html(data);
                          }
                  }); 
                }
            } else {
            
                $(".sort").css("display","block");
                var productName= $("#txtTenVP").val();
                var idCate = $("#SearchCategory").val();
                var dateTypeVar = $("#dateStart").datepicker("getDate");
                var dateStart=$.datepicker.formatDate("yy-mm-dd", dateTypeVar); 
                
                dateTypeVar = $("#dateStartEnd").datepicker("getDate");
                var dateStartEnd = $.datepicker.formatDate("yy-mm-dd", dateTypeVar);
                
                dateTypeVar = $("#dateEnd").datepicker("getDate");
                var dateEnd = $.datepicker.formatDate("yy-mm-dd", dateTypeVar);
                
                dateTypeVar = $("#dateEndEnd").datepicker("getDate");
                var dateEndEnd = $.datepicker.formatDate("yy-mm-dd", dateTypeVar);
                
                var sortby =$(".sortb").val(); 
                var rank =$(".sorta").val(); 
            
                $.ajax({
                        type: "post",
                        url:"/search/index",
                        data:{"productName":productName,"page":page_number,"sortby":sortby,"rank":rank,"idCategory":idCate,"dateStart":dateStart,"dateStartEnd":dateStartEnd,"dateEnd":dateEnd,"dateEndEnd":dateEndEnd},
                        async:false,
                        success:function(data)
                          {

                                 $(".maincontent").html(data);
                                  $("#boxSearch").toggle();
                          }
                  }); 
                
            }
	}
        
        function sort_onchange()
        {
            
            flag =1;
            sort(0);
            
        }
        function search_onchange()
        {
        
            flag =0;
            sort(0);
        }
       
        
  $(function() {
    $( "#dateStart" ).datepicker();
  });
   $(function() {
    $( "#dateStartEnd" ).datepicker();
  });
  $(function() {
    $( "#dateEnd" ).datepicker();
  });
   $(function() {
    $( "#dateEndEnd" ).datepicker();
  });
    
  /* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


